/*
 * Copyright (c) 2011 Vasile Vilvoiu. All rights reserved.
 *   
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * ferror.h - error handling routines
 */
#pragma once

#include "ftypes.h"

/* file and line macro */
#define __HERE__	__FILE__, __LINE__

/* error codes */
/* when adding new errors, make sure to update err_get_text in ferror.c */
#define ERR_NONE							 0
#define ERR_GENERIC							-1
#define ERR_OUT_OF_MEM						-2
#define ERR_BAD_PTR							-3

#define ERR_IO_FILE_WRITE_FAIL				-100
#define ERR_IO_FILE_READ_FAIL				-101

#define ERR_CFG_PARSE_ERROR					-200
#define ERR_CFG_BAD_VALUE					-201

#define ERR_WINSOCK_INIT_FAIL				-300

#define ERR_MAX_CONNECTIONS					-400
#define ERR_SOCKET_INVALID_PORT				-401
#define ERR_SOCKET_CREATE_FAIL				-402
#define ERR_SOCKET_BIND_FAIL				-403
#define ERR_SOCKET_CLOSE_FAIL				-404
#define ERR_SOCKET_LISTEN_FAIL				-405
#define ERR_SOCKET_ACCEPT_FAIL				-406

#define ERR_THREAD_CREATE_FAIL				-500


extern int err_init(const char *file_name, bool print_header);
extern int err_kill();
extern int err_clear();
extern int err_error(int code, const char *message, const char *file_name, int line);
extern int err_errorf(int code, const char *format, const char *file_name, int line, ...);
extern char* err_get_text(int code);